package com.software.sqlite.service.impl;

import com.software.sqlite.api.admin.v1.vo.AdminLoginUserVO;
import com.software.sqlite.api.admin.v1.vo.AdminV1Result;
import com.software.sqlite.common.BaseMapper;
import com.software.sqlite.entity.TbProductInfo;
import com.software.sqlite.mapper.TbProductInfoMapper;
import com.software.sqlite.service.ITbProductInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;

@Service
@Slf4j
public class TbProductInfoService extends BaseService<TbProductInfo,String,Object> implements ITbProductInfoService {
    @Resource
    private TbProductInfoMapper mapper;

    @Override
    protected BaseMapper<TbProductInfo> getBaseMapper() {
        return mapper;
    }

    @Override
    public TbProductInfo getByUUId(String uuid) {
        return mapper.getByUUId(uuid);
    }

    @Override
    public AdminV1Result edit(TbProductInfo model) {
        AdminV1Result adminV1Result=new AdminV1Result();
        int code=1;
        String msg="保存失败";
        try{
            if(model!=null){
                AdminLoginUserVO loginUser=this.getLoginUser(model.getToken());
                model.setUseStatus("normal");

                if(model.getProductId()==null || model.getProductId().equals(0L)){
                    String uuid= UUID.randomUUID().toString().toLowerCase();
                    model.setUuid(uuid);
                    model.setCreateTime(new Date());
                    model.setCreateAdminId(loginUser.getUserId());
                    mapper.insertSelective(model);
                }else{
                    model.setUpdateTime(new Date());
                    model.setUpdateAdminId(loginUser.getUserId());
                    model.setCreateTime(new Date());
                    model.setCreateAdminId(loginUser.getUserId());
                    update(model);
                }
                code=0;
                msg="保存成功";
            }
        }catch (Exception e){
            log.error(e.getMessage(),e);
        }
        adminV1Result.setMsg(msg);
        adminV1Result.setCode(code);
        return adminV1Result;
    }

    @Override
    public void importData(TbProductInfo model) throws Exception {

    }

    @Override
    public String exportData(TbProductInfo model) throws Exception {
        return null;
    }

    @Override
    public String[] uploadExcel(MultipartFile file, Map<String, Object> paramsMap, HttpServletRequest request) {
        return new String[0];
    }


}
